package stalker.room;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import message.Message;
import message.MessageParser;
import message.types.string.CreateRoomRequest;
import network.e2e.FrameReader;
import network.e2e.FrameWriter;
import network.link.FrameInputStream;
import network.link.FrameOutputStream;

import org.junit.Test;

import stalker.Stalker;
import stalker.user.User;


public class RoomManagerTest {
  
  /**
   * Tests for user connection
   * @throws IOException 
   */
  @Test
  public void testUserConnection() throws IOException {
    User apel = User.createUser("Manusia 1/2 Apel");
    Message test = new CreateRoomRequest(apel, Stalker.ROOM_MANAGER_STALKER, "");
    Message test2 = new CreateRoomRequest(apel, Stalker.ROOM_MANAGER_STALKER, "dolph");
    
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    FrameWriter fw = new FrameWriter(new FrameOutputStream(os));
    
    //register
    MessageParser.send(test, fw);
    
  //register
    MessageParser.send(test2, fw);
  //register
    MessageParser.send(test, fw);
    
    FrameReader fr = new FrameReader(new FrameInputStream(new ByteArrayInputStream(os.toByteArray())));
    
    System.out.println(os.toString());
    
    ByteArrayOutputStream osnet = new ByteArrayOutputStream();
    
    apel.activate(fr, new FrameWriter(new FrameOutputStream(osnet)));
    
    //System.out.println("Ending");
    try {
      Thread.sleep(100);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    System.out.println(osnet.toString());
    
//    Assert.assertEquals(stalk, test);
  }
  
}
